//
// Created by gd on 2019/12/1.
//

#include "transport.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include <unistd.h>

Transport::Transport() {

}
void Transport::send(const char* dst, int port, void *buf, int size) {
  int sock_fd;
  sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
  struct sockaddr_in addr_serv;
  int len;
  memset(&addr_serv, 0, sizeof(addr_serv));
  addr_serv.sin_family = AF_INET;
  addr_serv.sin_addr.s_addr = inet_addr(dst);
  addr_serv.sin_port = htons(port);
  len = sizeof(addr_serv);
  sendto(sock_fd, buf, size, 0, (struct sockaddr *)&addr_serv, len);
  close(sock_fd);
}
